package com.secure.orm.thirdPay;

import java.util.Map;

import com.secure.orm.enums.ThirdPayNotifyType;
import com.secure.orm.model.PayOrder;
import com.secure.orm.model.response.ViewData;

// 基本处理 第三方订单过程
public class BaseThirdPay {
	public BaseThirdPay() {

	}

	// 创建第三方支付请求表单
	public String buildRequestForm(PayOrder payOrder, String className) {
		IThirdPay thirdPay = getThirdPayInstance(className);
		return (String) thirdPay.pay(payOrder);
	}

	// 处理第三方 响应的response 数据
	public ViewData handleResponse(Map<String, String> reqMap, String className, ThirdPayNotifyType thirdPayNotifyType) {
		IThirdPay thirdPay = getThirdPayInstance(className);
		ViewData msg = (ViewData) thirdPay.handleResponse(reqMap,
				thirdPayNotifyType);
		return msg;
	}

	public ViewData queryPayInfo(Map<String, String> reqMap, String className, ThirdPayNotifyType thirdPayNotifyType) {
		IThirdPay thirdPay = getThirdPayInstance(className);
		ViewData msg = (ViewData) thirdPay.queryPayInfo(reqMap);
		return msg;
	}

	// 反射产生对应的 第三方支付实体
	public IThirdPay getThirdPayInstance(String className) {
		IThirdPay thirdPay = null;
		try {
			Class<?> cl = Class.forName(className);
			thirdPay = (IThirdPay) cl.getConstructor().newInstance();
		} catch (Exception e) {
			throw new RuntimeException();
		}
		return thirdPay;
	}
	
}
